package senpec.qc.harmony.system.role;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import senpec.qc.harmony.base.mybatisplus.IBaseControllerImpl;
import senpec.qc.harmony.base.mybatisplus.Result;

@RestController
@RequestMapping("/system/role")
public class RoleController extends IBaseControllerImpl<Role, RoleService> {
    private final RoleService roleService;

    public RoleController(RoleService baseService, RoleService roleService) {
        super(baseService);
        this.roleService = roleService;
    }

    @Override
    @PreAuthorize("hasRole('超级管理员')")
    public Result<Role> insertOne(Role entity) {
        return roleService.insertOne(entity);
    }

    @Override
    @PreAuthorize("hasRole('超级管理员')")
    public Result<?> physicalDeleteById(Long id) {
        return roleService.physicalDeleteById(id);
    }

    @Override
    @PreAuthorize("hasRole('超级管理员')")
    public Result<?> logicalDeleteById(@PathVariable("id") Long id) {
        return roleService.logicalDeleteById(id);
    }

    @Override
    @PreAuthorize("hasRole('超级管理员')")
    public Result<Role> updateOne(Role entity) {
        return roleService.updateOne(entity);
    }

    @PostMapping("/setRoleIdByUserId")
    public Result<?> setRoleIdByUserId(RoleDTO roleDTO) {
        return roleService.setRoleIdByUserId(roleDTO);
    }
}